package com.lelouch.controller;

import com.lelouch.bean.SysAclModule;
import com.lelouch.common.ApplicationContextHelper;
import com.lelouch.common.JsonData;
import com.lelouch.dao.SysAclModuleMapper;
import com.lelouch.exception.ParamException;
import com.lelouch.exception.PermissionException;
import com.lelouch.param.TestVo;
import com.lelouch.util.BeanValidator;
import com.lelouch.util.JsonMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 测试控制器
 *
 * @author lcy
 * @create 2018-06-09 09:57
 */
@Controller
@RequestMapping("/test")
@Slf4j
public class TestController {

    @RequestMapping("/hello")
    @ResponseBody
    public String testHello(){
        return "hello,permission!";
    }


    @RequestMapping("/exception.json")
    @ResponseBody
    public JsonData testException(){

        throw new PermissionException();
    }



    @RequestMapping("/validate.json")
    @ResponseBody
    public JsonData validate(TestVo vo) throws ParamException {
        log.info("validate");
        SysAclModuleMapper moduleMapper = ApplicationContextHelper.popBean(SysAclModuleMapper.class);
        SysAclModule module = moduleMapper.selectByPrimaryKey(1);
        log.info(JsonMapper.obj2String(module));
        BeanValidator.check(vo);
        return JsonData.success("test validate");
    }
}
